package main

import (
	"flag"
	"fmt"
	"git.huoys.com/middle-business/xds/internal/server"
	"git.huoys.com/middle-end/kratos/pkg/conf/paladin"
	api "github.com/envoyproxy/go-control-plane/envoy/api/v2"
	//discovery "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
	"log"
	"net"
)

func main() {
	flag.Parse()
	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", 9000))
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	paladin.Init(nil)
	server.InitServerDeps()
	s := grpc.NewServer()
	api.RegisterClusterDiscoveryServiceServer(s, &server.Server{})
	api.RegisterListenerDiscoveryServiceServer(s, &server.Server{})
	api.RegisterRouteDiscoveryServiceServer(s, &server.Server{})
	api.RegisterEndpointDiscoveryServiceServer(s, &server.Server{})
	//discovery.RegisterAggregatedDiscoveryServiceServer(s, &server.Server{})

	reflection.Register(s)

	log.Print("Started grpc server..")
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve %v", err)
	}
}
